# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
from lr.work.models import Work


class BookcaseManager(models.Manager):
    """ Менеджер создания нового книжного шкафа """
    
    def create_bookcase(self, user):
        """ Создать новый шкаф """
        bookcase = self.create(user=user)
        return bookcase



class Bookcase(models.Model):
    """ Книжный шкаф """
    user = models.OneToOneField(User, related_name='bookcase_user', verbose_name=u'Пользователь', primary_key=True)
    recommended = models.ManyToManyField(Work, blank=True, null=True, verbose_name=u'Рекомендованное', related_name='bookcase_recommended')
    favorites = models.ManyToManyField(Work, blank=True, null=True, verbose_name=u'Избранное', related_name='bookcase_favorites')
    
    objects = BookcaseManager()
    
    
    class Meta:
        verbose_name = u'Книжный шкаф'
        verbose_name_plural = u'Книжные шкафы'
    
    
    def __unicode__(self):
        """ Имя поля в админке """
        return self.user.username
        